<?php
if( !isset($params['body']) || !isset($params['total_fee']) || !isset($params['detail']) || !isset($params['out_trade_no'])){
    echo json_encode('参数错误');exit;
}

$baseUrl = 'https://api.rightyoo.net/v1/?service=Pay.Unifiedorder';
$key = '0d8226a1fe3cd661308f8e78e8c859dc';

$sendParams['app_id'] = 'W1571260';
$sendParams['mch_id'] = '100100109';
$sendParams['nonce_str'] = createRandom(32);
$sendParams['pay_channel'] = 'wechat';
$sendParams['out_trade_no'] = $params['out_trade_no'];
$sendParams['body'] = $params['body'];
$sendParams['total_fee'] = $params['total_fee'];
$sendParams['detail'] = $params['detail'];
$sendParams['spbill_create_ip'] = request()->ip();
$sendParams['notify_url'] = $params['callback_url'];
$sendParams['scene_info'] = 'wap_url=www.miyuhaiwai.com&wap_name=星趣米娱';
$sendParams['trade_type'] = 'H5';
$sendParams['product_id'] = '123';
$sendParams['sign'] = createSign($sendParams, $key);

$result = http($baseUrl, $sendParams, 'POST');

$decode = json_decode($result, true);
if($decode['ret'] == 200){
    $payUrl = $decode['data']['pay_url'];
    $newPayUrl = str_replace('ydsd.html', 'ydsdrd.html', $payUrl);
    $newPayUrl .= '&cburl='.$params['return_url'].'&pid='.time();
    return $newPayUrl;
    exit;
}else{
    return json_encode($decode['msg']);exit;
}

